#ifndef _CPU_PARSE_H
#define _CPU_PARSE_H
/*
 *  cpu_parse_display/cpu_parce.h
 *  
 *              CPU Monitor 
 *
 *    Spring Semester.  044800.    Technion.
 *   Copyright (C) 2006  Evgeny Shulman  and Elizabeth Shtrom 
 */

#include "../cpu_common.h"
#include "../cpu_consts.h"
 
typedef char  small_field[12];
typedef char  middle_field[20];
typedef char  big_field[50];

typedef struct _parsed_desc_struct{
	small_field   index , g ; 
	middle_field  status ,type,   base, limit,   dpl, sel, off,wc,   mode,type_1, type_2, db , entry ; 
}parsed_desc_s;

typedef struct _parsed_page_struct{
	small_field   index ,user, mode , dirty , accessed , sel, off,  global , pse , pwt , pcd , avail ; 
	middle_field  status ,frame, swp_offset, swp_type, entry; 
}parsed_page_s;

typedef struct _parsed_Xgt_struct{
	middle_field   address,size ; 
}parsed_Xgt_s;

typedef struct _parsed_regs_struct{
	middle_field cr0,cr3,cr4,cr2,dr0,dr1,dr2,dr3,dr4,dr5,dr6,dr7,cs,ss,es,ds,fs,gs,ldtr,tr;
    parsed_Xgt_s idtr, gdtr;
} parsed_regs_s;
    
typedef struct _parsed_tss_struct{
	small_field iobase , ldtsegsel, cs, ss, es, ds, fs, gs , edi, esi, ebp, esp, ebx, edx, ecx, eax, eflags, eip, \
	 cr3, ss2, esp2, ss1, esp1, ss0, esp0 , prevtask ;
} parsed_tss_s;


int parse_regs      (regs_s  *, parsed_regs_s *s);

 
int parse_gdt      (cm_desc_t      *gdt,parsed_desc_s *out, int sel,	int count);
int parse_ldt      (cm_desc_t      *gdt,parsed_desc_s *out, int sel,	int count);
int parse_idt      (cm_gate_desc_t *idt,parsed_desc_s *out, int vec,  int count );
int parse_pgdir    ( void * pgdir      ,parsed_page_s *out, int index , int count );
int parse_ptable   ( void * ptable     ,parsed_page_s *out, int index , int count );

#ifdef __KERNEL__ 	
	#include <asm/processor.h> 	
  int  parse_tss(parsed_tss_s *s , struct tss_struct  *t);
#else	
  int  parse_tss(parsed_tss_s *s , cm_tss_struct *t);
#endif

int parse_gate_desc(cm_gate_desc_t *,    parsed_desc_s *s );
int parse_seg_desc (cm_desc_t *     ,    parsed_desc_s *s );
int parse_Xgt( struct Xgt_desc_struct *, parsed_Xgt_s *s);

int parse_idt_stats(im_irq_stat_s *im_irq_stat_data);


#endif /*_CPU_PARSE_H*/

